<template>
  <div class="customer-management-page">
    <div class="search-wrapper">
      <super-search :search-form="searchForm" :search-item-config="searchItemList" @search="searchHandle"></super-search>
    </div>
    <div class="content-wrapper">
      <super-table
        :height="tableHeight"
        ref="tableRef"
        v-model:page="searchForm.pageNum"
        v-model:limit="searchForm.pageSize"
        :loading="loading"
        :data="tableData"
        :total="searchForm.total"
        :column="tableColumn"
        @change-page="getData"
      >
        <template #tool>
          <a-button type="primary" @click="addHandle" v-btnAuth="'CUSTOMERMANAGEMENT_ADD_CUSTOMER'">新增客户</a-button>
          <a-button type="default" @click="batchModifyHandle(1)" v-btnAuth="'CUSTOMERMANAGEMENT_BATCH_MODIFICATION_OF_BUSINESS'">批量修改业务</a-button>
          <a-button type="default" @click="batchModifyHandle(2)" v-btnAuth="'CUSTOMERMANAGEMENT_BATCH_MODIFICATION_OF_DOCUMENTATION'">批量修改跟单</a-button>
          <a-button type="primary" @click="exportHandle" v-btnAuth="'CUSTOMERMANAGEMENT_BATCH_EXPORT'">批量导出</a-button>
        </template>
        <template #status="{ row }">
          <a-tag v-if="row.status === 1" color="#87d068"> 启用 </a-tag>
          <a-tag v-if="row.status === 0" color="#cd201f"> 停用 </a-tag>
        </template>
        <template #action="{ row }">
          <a-button type="link" :danger="row.status === 1" @click="changeStatusHandle(row)" v-btnAuth="'CUSTOMERMANAGEMENT_STATUS'">{{ row.status === 0 ? "启用" : "停用" }}</a-button>
          <a-button type="link" @click="editHandle(row)" v-btnAuth="'CUSTOMERMANAGEMENT_EDIT'">编辑</a-button>
          <a-button type="link" @click="restCustomerPasswordHandle(row)">重置密码</a-button>

          <!-- <a-button type="link" @click="editHandle(row)">登录</a-button> -->
          <!-- <a-button type="link" @click="attachmentHandle(row)">附件管理</a-button> -->
        </template>
      </super-table>
    </div>
    <!-- 抽屉 -->
    <a-drawer v-model:visible="drawerOpts.visible" :title="drawerOpts.title" :maskClosable="false" :closable="true" :width="drawerOpts.width" placement="right">
      <component v-model:visible="drawerOpts.visible" :is="drawerOpts.component" :type="drawerOpts.type" :pass-data="drawerOpts.passData" @submit="drawerSubmitHandle"></component>
    </a-drawer>
    <a-modal v-model:visible="dialogOpts.visible" :maskClosable="false" :keyboard="false" :closable="false" :footer="null" :title="dialogOpts.title" :width="dialogOpts.width">
      <component v-model:visible="dialogOpts.visible" :is="dialogOpts.component" :type="dialogOpts.type" :pass-data="dialogOpts.passData" @submit="dialogSubmitHandle"></component>
    </a-modal>
  </div>
</template>
<script lang="ts">
import AddCustomer from "./components/addCustomer/index.vue";
import BatchModify from "./components/batchModify/index.vue";
export default {
  name: "CustomerManagement",
  components: {
    AddCustomer,
    BatchModify
  }
};
</script>
<script lang="ts" setup>
import TableHeightHook from "@/hook/tableHeightHook";
import ModalHook from "@/hook/modalHook";
import { searchItemList, tableColumn } from "./data";
import InitHook from "./composables/initHook";
import OperationHook from "./composables/operationHook";
const { tableHeight, loading } = TableHeightHook(50);
const { searchForm, tableData, drawerOpts, tableRef, dialogOpts } = InitHook();
const { searchHandle, getData, drawerSubmitHandle, addHandle, editHandle, changeStatusHandle, batchModifyHandle, exportHandle, restCustomerPasswordHandle } = OperationHook({
  searchForm,
  tableData,
  drawerOpts,
  tableRef,
  loading,
  dialogOpts
});
const { dialogSubmitHandle } = ModalHook({
  dialogOpts,
  callBack: getData
});
getData();
</script>
<style lang="stylus" scoped></style>
